package com.jiuwu.spring.eshop.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
public class UrlRequestInterceptor implements HandlerInterceptor {


    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        String handlerName = handler.getClass().getSimpleName();
        if(handler instanceof HandlerMethod){
            String beanTypeName = ((HandlerMethod) handler).getBeanType().getName();
            String methodName = ((HandlerMethod) handler).getMethod().getName();
            handlerName = beanTypeName + methodName;
        }
        log.info("[{}]-[{}]",request.getRequestURI(),handlerName);
    }
}
